﻿#include "force_data.h"


static bank3 int gForceData[CHANNEL_NUM];
bank3 int gForceData_Peak[CHANNEL_NUM];
bank3 int gForceData_Vally[CHANNEL_NUM];
bank3 int gForceData_Peak_Pre[CHANNEL_NUM];
bank3 int gForceData_Vally_Pre[CHANNEL_NUM];



int Get_ForceData(char ch_num)
{
	return gForceData[ch_num];
}
/**
 * @brief 记录force，计算最大最小值，记录前一次最大最小值
 * 
 */
void Record_Force(char ch_num)
{
	long temp_force;
	
	temp_force= Get_Rawdata(ch_num) - Get_Base_Line(ch_num);        //计算force
	temp_force *= gForceFactor[ch_num];
	temp_force /= 1024;
	gForceData[ch_num] = temp_force;	


	if(Get_Forceflag(ch_num) != NO_TOUCH)
	{
		if(gForceData[ch_num] > gForceData_Peak[ch_num])	// 更新绝对最大值
		{
			gForceData_Peak[ch_num] = gForceData[ch_num];    //力的峰值
		}
		if(gForceData[ch_num] < gForceData_Vally[ch_num])	// 更新绝对最大值
		{
			gForceData_Vally[ch_num] = gForceData[ch_num];    //力的峰值
		}	
	}else{
//		//离手第一帧记录前一次按压的峰值 
//		if(gRel_Times[ch_num] == 1)
//		{
//			gForceData_Peak_Pre[ch_num] = gForceData_Peak[ch_num];
//			gForceData_Vally_Pre[ch_num] = gForceData_Vally[ch_num];	
//		}
	
		gForceData_Peak[ch_num] = 0;
		gForceData_Vally[ch_num] = 0;
		
//		if(gRel_Times[ch_num] == 200)
//		{
//			gForceData_Peak_Pre[ch_num]  = 0;
//			gForceData_Vally_Pre[ch_num]  = 0;
//		}
		
	}

		
}
/**
 * @brief 计算力值过程
 * 
 */
void Force_Data_Process()
{
	char i;
	for(i =0 ;i<CHANNEL_NUM;i++)
	{
		//记录force
		Record_Force(i); 	
	}
	
	
}